package core.proto.search;

import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException;

import core.proto.AllComponents;

public class NotesAreaSearchDocumentListener implements DocumentListener{

	@Override
	public void changedUpdate(DocumentEvent e) {
		// No op.
	}

	@Override
	public void insertUpdate(DocumentEvent e) {
		try {
			search(e.getDocument().getText(0, e.getDocument().getLength()));
		} catch (BadLocationException ble) {
			throw new Error(ble);
		}
	}

	@Override
	public void removeUpdate(DocumentEvent e) {
		try {
			search(e.getDocument().getText(0, e.getDocument().getLength()));
		} catch (BadLocationException ble) {
			throw new Error(ble);
		}
	}
	
	void search(String searchText){
		AllComponents.getNotesArea().setSearchString(searchText);
		AllComponents.getNotesArea().getTable().repaint();
	}

}
